<?php slot('sub', $sub); ?>

<div class="center">
    <div id="center_conteiner" class="clearfix">
        <div class="center_sub_conteiner">

            <div class="center_block">
                <div class="header_center_block">
                    <span>Edit hotel <?php echo $hotel->getNameEn(); ?></span>
                    <div class="back_button"><a href="<?php echo url_for('hoteldetails', array('id' => $hotel->getId())); ?>">Back</a></div>
                </div>

                <div class="center_line" id="edit_hotel_id">
                    <div class="field_label">Hotel ID</div>
                    <input type="text" class="field_input" value="<?php echo $hotel->getId(); ?>" readonly>
                </div>

                <div class="center_line" id="edit_hotel_en">
                    <div class="field_label">Name in English</div>
                    <input type="text" class="field_input" value="<?php echo $hotel->getNameEn(); ?>">
                </div>

                <div class="center_line"  id="edit_hotel_ru">
                    <div class="field_label">Name in Russian</div>
                    <input type="text" class="field_input" value="<?php echo $hotel->getNameRu(); ?>">
                </div>

                <div class="center_line" id="edit_hotel_he">
                    <div class="field_label">Name in Hebrew</div>
                    <input type="text" class="field_input" value="<?php echo $hotel->getNameHe(); ?>">
                </div>

                <div class="center_line" id="edit_hotel_stars">
                    <div class="field_label">Stars</div>
                    <div class="field_stars">
                        <ul>
                            <?php
                            $stars = $hotel->getStars();
                            $starsOn = true;
                            $selected = false;
                            for ($i = 0; $i < 5; $i++) {
                                if ($i + 1 > $stars) {
                                    $starsOn = false;
                                }

                                if ($i + 1 == $stars) {
                                    $selected = true;
                                }

                                if ($starsOn) {
                                    if ($selected) {
                                        $selected = false;
                                        echo '<li value="' . ($i + 1) . '" selected="selected"><img src="/web/images/icoStar.png"></li>';
                                    } else {
                                        echo '<li value="' . ($i + 1) . '"><img src="/web/images/icoStar.png"></li>';
                                    }
                                } else {
                                    echo '<li value="' . ($i + 1) . '"><img src="/web/images/icoGreyStar.png"></li>';
                                }
                            }
                            ?>
                        </ul>
                    </div>
                </div>

                <div class="center_line" id="edit_hotel_country">
                    <div class="field_label">Country</div>
                    <select class="field_select">
                        <?php
                        foreach ($country as $c) {
                            if ($hotel->getCountryId() == $c->getId()) {
                                echo "<option selected='selected' value='" . $c->getId() . "'>" . $c->getNameEn() . "</option>";
                            } else {
                                echo "<option value='" . $c->getId() . "'>" . $c->getNameEn() . "</option>";
                            }
                        }
                        ?>
                    </select>
                </div>

                <div class="center_line" id="edit_hotel_region">
                    <div class="field_label">Region</div>
                    <select class="field_select"></select>
                </div>

                <div class="center_line" id="edit_hotel_city">
                    <div class="field_label">City</div>
                    <select class="field_select">
                    </select>
                </div>

                <script  type="text/javascript">
                    var cregion = '<?php echo $hotel->getRegionId() ?>';
                    var ccity = '<?php echo $hotel->getCityId() ?>';
                    var regions = [];
                    var cites = [];
<?php foreach ($region as $r) { ?>
                        var temp = {
                            id: '<?php echo $r->getId() ?>',
                            nameEn: '<?php echo $r->getNameEn() ?>',
                            country_id: '<?php echo $r->getCountryId() ?>'
                        };

                        regions.push(temp);
<?php } ?>

<?php foreach ($city as $c) { ?>
                        var temp = {
                            id: '<?php echo $c->getId() ?>',
                            nameEn: '<?php echo $c->getNameEn() ?>',
                            country_id: '<?php echo $c->getCountryId() ?>',
                            region_id: '<?php echo $c->getRegionId() ?>'
                        };

                        cites.push(temp);
<?php } ?>

                    $(function() {
                        insertRegions($('#edit_hotel_country select').val(), cregion);
                        insertCity($('#edit_hotel_country select').val(), cregion, ccity);

                        $('#edit_hotel_country select').change(function() {
                            countryId = $(this).val();
                            insertRegions(countryId, 0);
                            setTimeout(function() {
                                insertCity(countryId, $('#edit_hotel_region select').val(), 0);
                            }, 200);
                        });

                        $('#edit_hotel_region select').change(function() {
                            insertCity($('#edit_hotel_country select').val(), $(this).val(), 0);
                        });
                    });

                    function insertCity(country_id, region_id, city_id) {
                        $('#edit_hotel_city select option').remove();
                        var parentSelect = $('#edit_hotel_city select');
                        $.each(cites, function(i, v) {
                            if (parseInt(v.country_id) === parseInt(country_id)) {
                                if (parseInt(v.region_id) === parseInt(region_id)) {
                                    if (parseInt(city_id) === parseInt(v.id)) {
                                        (parentSelect).append('<option value="' + v.id + '" selected="selected">' + v.nameEn + '</option>');
                                    } else {
                                        (parentSelect).append('<option value="' + v.id + '">' + v.nameEn + '</option>');
                                    }
                                }
                            }
                        });
                    }

                    function insertRegions(country_id, region) {
                        $('#edit_hotel_region select option').remove();
                        var parentSelect = $('#edit_hotel_region select');

                        $.each(regions, function(i, v) {
                            if (parseInt(v.country_id) === parseInt(country_id)) {
                                if (parseInt(region) === parseInt(v.id)) {
                                    (parentSelect).append('<option value="' + v.id + '" selected="selected">' + v.nameEn + '</option>');
                                } else {
                                    (parentSelect).append('<option value="' + v.id + '">' + v.nameEn + '</option>');
                                } 
                            } 
                        });
                    }
                </script>

                <div class="center_line" id="edit_hotel_provider">
                    <div class="field_label">Provider</div>
                    <select class="field_select">
                        <?php
                        foreach ($provider as $c) {
                            echo "<option value='" . $c->getId() . "'>" . $c->getShortName() . "</option>";
                        }
                        ?>
                    </select>
                </div>

                <div class="center_line" id="edit_hotel_address">
                    <div class="field_label">Address</div>
                    <input type="text" class="field_input" value="<?php echo $hotel->getAddress(); ?>">
                </div>

                <div class="center_line" id="edit_hotel_phone1">
                    <div class="field_label">Phone</div>
                    <input type="text" class="field_input" value="<?php echo $hotel->getPhone1(); ?>">
                </div>

                <div class="center_line" id="edit_hotel_phone2">
                    <div class="field_label">Phone</div>
                    <input type="text" class="field_input" value="<?php echo $hotel->getPhone2(); ?>">
                </div>

                <div class="center_line" id="edit_hotel_fax">
                    <div class="field_label">Fax</div>
                    <input type="text" class="field_input" value="<?php echo $hotel->getFax(); ?>">
                </div>

                <div class="center_line" id="edit_hotel_email">
                    <div class="field_label">E-mail</div>
                    <input type="text" class="field_input" value="<?php echo $hotel->getEmail(); ?>">
                </div>

                <div class="center_line" id="edit_hotel_web">
                    <div class="field_label">Web Site</div>
                    <input type="text" class="field_input"  value="<?php echo $hotel->getWebSite(); ?>">
                </div>

                <div class="center_line_large" id="edit_hotel_descripton_en">
                    <div class="field_label">Description in English</div>
                    <textarea rows="5" cols="45" name="text" class="field_textarea" placeholder="text here...">
                        <?php echo $hotel->getDescriptionEn(); ?>
                    </textarea>
                </div>

                <div class="center_line_large" id="edit_hotel_descripton_ru">
                    <div class="field_label">Description in Russian</div>
                    <textarea rows="5" cols="45" name="text" class="field_textarea" placeholder="text here...">
                        <?php echo $hotel->getDescriptionRu(); ?>
                    </textarea>
                </div>

                <div class="center_line_large" id="edit_hotel_descripton_he">
                    <div class="field_label">Description in Hebrew</div>
                    <textarea rows="5" cols="45" name="text" class="field_textarea" placeholder="text here...">
                        <?php echo $hotel->getDescriptionHe(); ?>
                    </textarea>
                </div>

                <div class="center_line_big" id="edit_hotel_photo">
                    <div class="center_line_photo_add"></div>
                    <div class="photos_container">
                        <?php
                        $photos = $hotel->getPhoto();
                        $p = explode(";", $photos);
                        for ($i = 0; $i < count($p) - 1; $i++) {
                            echo '<div class="center_line_photo">' .
                            '<div class="center_line_photo_del"></div>' .
                            '<img class="image_hotel" src="' . $p[$i] . '"/>' .
                            '</div>';
                        }
                        ?>
                    </div>
                </div>

                <div class="center_line" id="edit_hotel_priority">
                    <div class="field_label">Priority</div>
                    <select class="field_select">
                        <?php
                        if ($hotel->getPriority() == 10) {
                            echo '<option selected="selected" value="10">Very small</option>';
                        } else {
                            echo '<option value="10">Very small</option>';
                        }

                        if ($hotel->getPriority() == 20) {
                            echo '<option selected="selected" value="20">Small</option>';
                        } else {
                            echo '<option value="20">Small</option>';
                        }

                        if ($hotel->getPriority() == 30) {
                            echo '<option selected="selected" value="30">Normal</option>';
                        } else {
                            echo '<option value="30">Normal</option>';
                        }

                        if ($hotel->getPriority() == 40) {
                            echo '<option selected="selected" value="40">High</option>';
                        } else {
                            echo '<option value="40">High</option>';
                        }

                        if ($hotel->getPriority() == 50) {
                            echo '<option selected="selected" value="50">Very high</option>';
                        } else {
                            echo '<option value="50">Very high</option>';
                        }
                        ?>
                    </select>
                </div>

                <div class="center_line">
                    <div class="field_button_positive" id="edit_hotel_save">Save</div>
                    <div class="field_button_negative" id="edit_hotel_cancel"><a href="<?php echo url_for('hoteldetails', array('id' => $hotel->getId())); ?>">Cancel</a></div>
                </div>

            </div>
        </div>
    </div>
</div>

